package com.android.pocketguru;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Vibrator;



public class AlarmReceiver extends BroadcastReceiver {

	
    @Override
    public void onReceive(Context context, Intent intent) {

		boolean isRecurring = intent.getExtras().getBoolean(Constants.POPUP_RECURRING_KEY);
		boolean asDialog = intent.getExtras().getBoolean(Constants.POPUP_AS_DIALOG_KEY);
		int alarmRequerstCode = intent.getExtras().getInt(Constants.ALARM_REQUEST_CODE_KEY);

		// Play notification sound. Uses Ringtone volume.
		Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
		Ringtone r = RingtoneManager.getRingtone(context, notification);
		r.play();
		
		// Get instance of Vibrator from current Context
		Vibrator v = (Vibrator) context.getSystemService(Activity.VIBRATOR_SERVICE);
		v.vibrate(300); // Vibrate for 300 milliseconds
    	
    	
        Intent i = new Intent(context, PopupActivity.class);
		i.putExtra(Constants.POPUP_AS_DIALOG_KEY, asDialog);
		i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
        
		if (isRecurring)
			AlarmHandler.setRecurringAlarm(context, alarmRequerstCode, asDialog);
    }

	
	
}
